package repository;

import annotation.DependencyInjection;
import annotation.Singleton;
import database.GroupDatabase;
import entity.Group;

import java.util.UUID;

@Singleton
public class GroupRepository {
    private GroupDatabase database;

    @DependencyInjection
    public GroupRepository(GroupDatabase database) {
        this.database = database;
    }

    public void startWrite() {
        database.startWrite();
    }

    public void endWrite() {
        database.endWrite();
    }

    public void startRead() {
        database.startRead();
    }

    public void endRead() {
        database.endRead();
    }


    public void add(Group group) {
        database.getList().add(group);
    }

    public Group getByUuid(UUID groupId) {
        Group result = database.getList().stream().filter(group -> group.getUuid().equals(groupId)).map(Group::new).findAny().orElse(null);
        return result;
    }
}
